cat('Creating Table A28 \n\n')

dat = read.csv('TableA28_data.csv')
dat.uo = dat[dat$uo.non.uo == 'uo',]
dat.sec = dat[dat$uo.non.uo != 'uo',]

##formulas specific to trust
use.formula = as.formula(paste('outgroup.distrust.cont ~ ',master.formula,sep = ''))
use.formula.reduced = as.formula(paste('outgroup.distrust.cont ~ ',master.formula.reduced,sep = ''))
use.formula.interactions = as.formula(paste('outgroup.distrust.cont ~ ',master.formula.interactions,sep = ''))

##UO
##regressions
reg.uo.pub = lm(use.formula, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub, dat.uo$index.city)
reg.uo.pub$se = clustered.se

reg.uo.pub.reduced = lm(use.formula.reduced, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub.reduced, dat.uo$index.city)
reg.uo.pub.reduced$se = clustered.se

reg.uo.pub.interactions = lm(use.formula.interactions, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub.interactions, dat.uo$index.city)
reg.uo.pub.interactions$se = clustered.se

##Secular
##regressions
reg.sec.pub = lm(use.formula, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub, dat.sec$index.city)
reg.sec.pub$se = clustered.se

reg.sec.pub.reduced = lm(use.formula.reduced, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub.reduced, dat.sec$index.city)
reg.sec.pub.reduced$se = clustered.se

reg.sec.pub.interactions = lm(use.formula.interactions, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub.interactions, dat.sec$index.city)
reg.sec.pub.interactions$se = clustered.se

outtable = apsrtable(reg.uo.pub.reduced,
                     reg.uo.pub,
                     reg.uo.pub.interactions,
                     reg.sec.pub.reduced,
                     reg.sec.pub, 
                     reg.sec.pub.interactions,
                     Sweave = T,
                     stars = 'default',
                     coef.names = coef.names,
                     model.names = c('UO','UO','UO','Non UO','Non UO','Non UO'),
                     notes = ''
                      )
writeLines(
  outtable, 'TableA28.tex')